home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / (Notes) / Fast blitting.doc < prev    next >
Text File  |  1996-01-25  |  29KB  |  731 lines

  1. C.S.M.P. Digest             Tue, 19 Dec 95       Volume 3 : Issue 128
  2. >From erichsen@pacificnet.net (Erichsen)
  3. Subject: Doubles Vs BlockMove
  4. Date: 16 Nov 1995 02:22:08 GMT
  5. Organization: Disorganized
  6.  
  7. I did some tests (modifying the code in MoveData app from Tricks of the
  8. Mac Game Programming Gurus) between using doubles in a loop and BlockMove
  9. in a loop and BlockMove still blew it away (200 ticks vs 146 ticks for
  10. BlockMove) so why don't more people use BlockMove?
  11.  
  12. I compared BlockMove vs BlockMoveData and found no difference at all (both
  13. 146 ticks). Does BlockMove not flush the cache on a 6100?
  14.  
  15. One of the replies to my previous question of why people don't just use
  16. BlockMove instead of a copying loop was that the data is not necessarily a
  17. block but, all the examples of blitters I've seen just copy one contiguous
  18. block of memory to another contiguous block of memory. Why couldn't
  19. BlockMove be used?
  20.  
  21. +++++++++++++++++++++++++++
  22.  
  23. >From cameron_esfahani@powertalk.apple.com (Cameron Esfahani)
  24. Date: Mon, 20 Nov 1995 11:55:46 -0800
  25. Organization: Apple Computer, Inc.
  26.  
  27. BlockMove/BlockMoveData on the first generation PPC are exactly the same
  28. function.  The reason that BlockMoveData was created in the first place
  29. was you could tell the system you were not moving code around and to not
  30. flush the instructino cache.  Since the 601 has a unified cache, this
  31. means that you don't have to worry about cache-coherency.  This means you
  32. don't have to flush the processor cache.
  33.  
  34. The reason most people don't use BlockMove/BlockMoveData as a blitter is
  35. that it will be very very slow if you ever use the screen as the
  36. destination.  The reason is that the BlockMove/BlockMoveData routines use
  37. the PPC instruction DCBZ.  This instruction will cause a data-exception
  38. fault if the address supplied is not copy-back cacheable.  The screen
  39. isn't marked copy-back cacheable.
  40.  
  41. Hope this helps,
  42. Cameron Esfahani
  43. ********
  44. >From nporcino@sol.uvic.ca (Nick Porcino)
  45. Date: 20 Nov 1995 20:35:30 GMT
  46. Organization: Planet IX
  47.  
  48. We did some tests and found on a Q700 that BlockMoveData was faster than
  49. BlockMove in the context of an actual game (Riddle of Master Lu)
  50.  
  51. - Nick Porcino
  52. Lead Engine Guy
  53. Sanctuary Woods
  54.  
  55. +++++++++++++++++++++++++++
  56.  
  57. >From meggs@virginia.edu (Andrew Meggs)
  58. Date: Tue, 21 Nov 1995 02:55:08 GMT
  59. Organization: University of Virginia
  60.  
  61. In article <erichsen-1511951722510001@pm2-3.pacificnet.net>,
  62. erichsen@pacificnet.net (Erichsen) wrote:
  63.  
  64. > I did some tests (modifying the code in MoveData app from Tricks of the
  65. > Mac Game Programming Gurus) between using doubles in a loop and BlockMove
  66. > in a loop and BlockMove still blew it away (200 ticks vs 146 ticks for
  67. > BlockMove) so why don't more people use BlockMove?
  68.  
  69. This got me interested, so I went and disassembled BlockMove. Surprisingly,
  70. they aren't using doubles:
  71.  
  72.   BlockMove
  73.      +00060 40A1C558   lwz        r5,0x0000(r3) 
  74.      +00064 40A1C55C   lwz        r6,0x0004(r3)
  75.      +00068 40A1C560   lwz        r7,0x0008(r3)
  76.      +0006C 40A1C564   lwz        r8,0x000C(r3)
  77.      +00070 40A1C568   lwz        r9,0x0010(r3) 
  78.      +00074 40A1C56C   lwz        r10,0x0014(r3)
  79.      +00078 40A1C570   lwz        r11,0x0018(r3)
  80.      +0007C 40A1C574   lwz        r12,0x001C(r3)
  81.      +00080 40A1C578   dcbz       0,r4          
  82.      +00084 40A1C57C   addi       r3,r3,0x0020  
  83.      +00088 40A1C580   dcbt       0,r3          
  84.      +0008C 40A1C584   stw        r5,0x0000(r4) 
  85.      +00090 40A1C588   stw        r6,0x0004(r4) 
  86.      +00094 40A1C58C   stw        r7,0x0008(r4)
  87.      +00098 40A1C590   stw        r8,0x000C(r4) 
  88.      +0009C 40A1C594   stw        r9,0x0010(r4)
  89.      +000A0 40A1C598   stw        r10,0x0014(r4)
  90.      +000A4 40A1C59C   stw        r11,0x0018(r4) 
  91.      +000A8 40A1C5A0   stw        r12,0x001C(r4) 
  92.      +000AC 40A1C5A4   addi       r4,r4,0x0020  
  93.      +000B0 40A1C5A8   bdnz       BlockMove+00060
  94.  
  95.  
  96. The performance win is in the dcbz/dcbt pair. I'm assuming you weren't
  97. copying to video memory, because that's marked uncacheable, and dcbz will
  98. severely hurt performance if your destination is uncacheable.
  99.  
  100. I probably would have written it more like this, personally. Does anyone
  101. have any idea what makes Apple's better? (Assuming it is...)
  102.  
  103. ;assume source, destination, and size are all 32-byte aligned
  104. ;set r3 to source address minus 8 and r4 to destination address minus 8
  105. ;set ctr to size >> 5
  106.  
  107. BlockMoveLoop
  108.    lfd      fp0,8(r3)
  109.    lfd      fp1,16(r3)
  110.    lfd      fp2,24(r3)
  111.    lfdu     fp3,32(r3)
  112.    dcbz     0,r4
  113.    dcbt     0,r3
  114.    stfd     fp0,8(r4)
  115.    stfd     fp1,16(r4)
  116.    stfd     fp2,24(r4)
  117.    stfdu    fp3,32(r4)
  118.    bdnz     BlockMoveLoop
  119.  
  120. > I compared BlockMove vs BlockMoveData and found no difference at all (both
  121. > 146 ticks). Does BlockMove not flush the cache on a 6100?
  122.  
  123. The unified instruction and data cache on the 601 wouldn't cause any
  124. problems with treating code as data, so there's no need to maintain
  125. coherency between the two. In other words, it shouldn't, but on the
  126. 604 it would need to.
  127.  
  128. -- 
  129. _________________________________________________________________________
  130. andrew meggs                               the one who dies with the most
  131. meggs@virginia.edu                              AOL free trial disks wins
  132. _________________________________________________________________________
  133. dead tv software --==-- the next generation of 3D games for the macintosh
  134.        <http://darwin.clas.virginia.edu/~apm3g/deadtv/index.html>
  135.  
  136. +++++++++++++++++++++++++++
  137.  
  138. >From Mark Williams <Mark@streetly.demon.co.uk>
  139. Date: Wed, 22 Nov 95 09:42:32 GMT
  140. Organization: Streetly Software
  141.  
  142.  
  143. In article <meggs-2011952155080001@bootp-188-82.bootp.virginia.edu>, Andrew Meggs writes:
  144.  
  145. > In article <erichsen-1511951722510001@pm2-3.pacificnet.net>,
  146. > erichsen@pacificnet.net (Erichsen) wrote:
  147. > > I did some tests (modifying the code in MoveData app from Tricks of the
  148. > > Mac Game Programming Gurus) between using doubles in a loop and BlockMove
  149. > > in a loop and BlockMove still blew it away (200 ticks vs 146 ticks for
  150. > > BlockMove) so why don't more people use BlockMove?
  151. > > 
  152. > This got me interested, so I went and disassembled BlockMove. Surprisingly,
  153. > they aren't using doubles:
  154. >   BlockMove
  155. >      +00060 40A1C558   lwz        r5,0x0000(r3) 
  156. >      +00064 40A1C55C   lwz        r6,0x0004(r3)
  157. >      +00068 40A1C560   lwz        r7,0x0008(r3)
  158. >      +0006C 40A1C564   lwz        r8,0x000C(r3)
  159. >      +00070 40A1C568   lwz        r9,0x0010(r3) 
  160. >      +00074 40A1C56C   lwz        r10,0x0014(r3)
  161. >      +00078 40A1C570   lwz        r11,0x0018(r3)
  162. >      +0007C 40A1C574   lwz        r12,0x001C(r3)
  163. >      +00080 40A1C578   dcbz       0,r4          
  164. >      +00084 40A1C57C   addi       r3,r3,0x0020  
  165. >      +00088 40A1C580   dcbt       0,r3          
  166. >      +0008C 40A1C584   stw        r5,0x0000(r4) 
  167. >      +00090 40A1C588   stw        r6,0x0004(r4) 
  168. >      +00094 40A1C58C   stw        r7,0x0008(r4)
  169. >      +00098 40A1C590   stw        r8,0x000C(r4) 
  170. >      +0009C 40A1C594   stw        r9,0x0010(r4)
  171. >      +000A0 40A1C598   stw        r10,0x0014(r4)
  172. >      +000A4 40A1C59C   stw        r11,0x0018(r4) 
  173. >      +000A8 40A1C5A0   stw        r12,0x001C(r4) 
  174. >      +000AC 40A1C5A4   addi       r4,r4,0x0020  
  175. >      +000B0 40A1C5A8   bdnz       BlockMove+00060
  176. > The performance win is in the dcbz/dcbt pair. I'm assuming you weren't
  177. > copying to video memory, because that's marked uncacheable, and dcbz will
  178. > severely hurt performance if your destination is uncacheable.
  179. > I probably would have written it more like this, personally. Does anyone
  180. > have any idea what makes Apple's better? (Assuming it is...)
  181.  
  182. consecutive stfd's stall both pipelines. This means that (assuming all cache hits) you get one fp 
  183. store every 3 cycles, compared with one integer store every cycle. The result is 12 cycles to 
  184. transfer 4 words using fp registers, but only 10 cycles using integer registers. (see page I-175 of 
  185. the 601 User manual).
  186.  
  187. > ;assume source, destination, and size are all 32-byte aligned
  188. > ;set r3 to source address minus 8 and r4 to destination address minus 8
  189. > ;set ctr to size >> 5
  190. > BlockMoveLoop
  191. >    lfd      fp0,8(r3)
  192. >    lfd      fp1,16(r3)
  193. >    lfd      fp2,24(r3)
  194. >    lfdu     fp3,32(r3)
  195. >    dcbz     0,r4
  196. >    dcbt     0,r3
  197. >    stfd     fp0,8(r4)
  198. >    stfd     fp1,16(r4)
  199. >    stfd     fp2,24(r4)
  200. >    stfdu    fp3,32(r4)
  201. >    bdnz     BlockMoveLoop
  202.  
  203. One other problem with your code (and presumably why apple use the apparently wasteful addi 
  204. instructions rather than load/store with update) is that your dcbt instruction comes too late... fp3 
  205. already contains the double at r3 by the time you hit the dcbt 0,r3 instruction, so it has no 
  206. effect. Much worse, the dcbz always touches the block you wrote the _previous_ time through the 
  207. loop...
  208.  
  209. this could easily be fixed by preloading r5 with 8 and writing
  210.  
  211.     dcbz     r5,r4
  212.     dcbt     r5,r3
  213.  
  214. But you would still lose out on a 601. I _think_ it would be quicker on a 604, but i've not 
  215. checked.
  216. - --------------------------------------
  217. Mark Williams<Mark@streetly.demon.co.uk>
  218.  
  219. +++++++++++++++++++++++++++
  220.  
  221. >From cameron_esfahani@powertalk.apple.com (Cameron Esfahani)
  222. Date: Tue, 28 Nov 1995 01:24:06 -0800
  223. Organization: Apple Computer, Inc.
  224.  
  225. BlockMoveData was introduced with System 7.5.  The code for
  226. it was kicking around Apple for a little while before we had a shipping
  227. vehicle for it.
  228.  
  229. Cameron Esfahani
  230.  
  231. +++++++++++++++++++++++++++
  232.  
  233. >From deirdre@deeny.mv.com (Deirdre)
  234. Date: Tue, 28 Nov 1995 14:46:04 GMT
  235. Organization: Tarla's Secret Clench
  236.  
  237. BlockMove was available in System 1.0. However, the distinction between
  238. BlockMove and the newer call BlockMoveData is only significant on 040s and
  239. higher. On other machines it is the same trap.
  240.  
  241. _Deirdre
  242.  
  243. +++++++++++++++++++++++++++
  244.  
  245. >From kenp@nmrfam.wisc.edu (Ken Prehoda)
  246. Date: Wed, 29 Nov 1995 09:26:05 -0600
  247. Organization: Univ of Wisconsin-Madison, Dept of Biochemistry
  248.  
  249. As far as I can tell BlockMoveData is _only_ significant on the 040. 
  250. BlockMove does not flush the cache on the PPC's.
  251. _____________________________________________________________________________
  252. Ken Prehoda                                              kenp@nmrfam.wisc.edu
  253. Department of Biochemistry                         http://www.nmrfam.wisc.edu
  254. University of Wisconsin-Madison                             Tel: 608-263-9498
  255. 420 Henry Mall                                              Fax: 608-262-3453
  256.  
  257. +++++++++++++++++++++++++++
  258.  
  259. >From cameron_esfahani@powertalk.apple.com (Cameron Esfahani)
  260. Date: Wed, 29 Nov 1995 22:53:41 -0800
  261. Organization: Apple Computer, Inc.
  262.  
  263. > As far as I can tell BlockMoveData is _only_ significant on the 040. 
  264. > BlockMove does not flush the cache on the PPC's.
  265.  
  266. That is not true.  BlockMove does flush the cache on the new PPCs.  Any
  267. PPC with a split cache (603/604 and any other ones) will require cache
  268. flushing.  So,  BlockMove on a 601-based machine doesn't flush the cache
  269. because it makes no sense, but on > 601-machines, it does flush.
  270.  
  271. Cameron Esfahani
  272.  
  273. +++++++++++++++++++++++++++
  274.  
  275. >From mick@emf.net (Mick Foley)
  276. Date: Wed, 29 Nov 1995 22:23:29 -0800
  277. Organization: "emf.net" Quality Internet Access.  (510) 704-2929 (Voice)
  278.  
  279. > As far as I can tell BlockMoveData is _only_ significant on the 040. 
  280. > BlockMove does not flush the cache on the PPC's.
  281.  
  282. Not on the 601 which has a unified cache. But it should make a big
  283. difference on the 603 and 604 which have split data and code caches.
  284.  
  285. Mick
  286.  
  287. +++++++++++++++++++++++++++
  288.  
  289. >From Ed Wynne <arwyn@engin.umich.edu>
  290. Date: 4 Dec 1995 04:09:26 GMT
  291. Organization: Arwyn, Inc.
  292.  
  293. Actually, thats almost right...  BlockMoveData CAN cause cache flushing on
  294. 601-based machines if they are running the DR emulator.  The processor
  295. cache doesn't get flushed but the emulator's internal cache of recompiled code
  296. does.  This process is probably a fair amount slower than the real on-chip
  297. cache flush since it is a software based operation.
  298.  
  299. To my knowledge the only machines so-far with this configuration would be
  300. the 7200 and 7500.  (does the 8500 have a 601 option?)
  301.  
  302. -ed
  303.  
  304. ---------------------------
  305.  
  306. C.S.M.P. Digest             Tue, 26 Dec 95       Volume 3 : Issue 129
  307.  
  308. ---------------------------
  309.  
  310. >From steele@isi.edu (Craig S. Steele)
  311. Subject: Block copy on 604 slow
  312. Date: Tue,  5 Dec 1995 18:30:53 -0800
  313. Organization: USC Information Sciences Institute
  314.  
  315. I'm trying to benchmark block copy rates of various sizes for PowerPCs.  My 
  316. results are disappointing for the 604, and cause me to wonder what it is I 
  317. don't understand. Testing on a 9500/120, to which I have limited access, gives 
  318. the following results for copy code using 32-bit integer and 64-bit double 
  319. load and stores, respectively:
  320.  
  321. Asm lvector copy of  1024 doubles in  44.8 nS/acc,  5.4 clocks/acc,  85.1 MB/s
  322. Asm dvector copy of  1024 doubles in  34.1 nS/acc,  4.1 clocks/acc, 111.9 MB/s
  323.  
  324. The source array is aligned to 4K, the destination array to 4K+0x100, to avoid 
  325. possible aliasing interlocks.  The source array is preloaded immediately 
  326. before the copy routine is called, so I would expect everything to run at L1 
  327. cache rates.
  328.  
  329. I would naively expect the copy code to average about 1.5 clocks per load or 
  330. store.  Instead, my code reports over 4 clocks/access.  The code uses the 
  331. time-base register for timing, which shouldn't cause significant cache 
  332. disturbance.
  333.  
  334. Can anyone contradict, corroborate, or explain my poor results? If I can't do 
  335. better than this, we'll have to build extra hardware :-(
  336. Thanks in advance.
  337. -Craig
  338.  
  339.     exportf2    dvec_copy
  340.     mtctr    r5        ; init loop counter
  341.     addi    r3,r3,-8    ; predecrement pointer by double size
  342.     addi    r4,r4,-8    ; predecrement pointer by double size
  343.     li    r6,8        ; cache line alignment constant for dcbz
  344.     b    dvc_1
  345.     align    6
  346. dvc_1
  347.     dcbz    r6,r3        ; kill dest. cache line
  348.     lfd    fp0,8(r4)
  349.     lfd    fp1,16(r4)
  350.     lfd    fp2,24(r4)
  351.     lfdu    fp3,32(r4)
  352.     stfd    fp0,8(r3)
  353.     stfd    fp1,16(r3)
  354.     stfd    fp2,24(r3)
  355.     stfdu    fp3,32(r3)
  356.     bdnz    dvc_1        ; test loop condition
  357.     blr
  358.  
  359.  
  360.  
  361. Craig S. Steele - Not yet Institutionalized
  362.  
  363.  
  364.  
  365. +++++++++++++++++++++++++++
  366.  
  367. >From rbarris@netcom.com (Robert Barris)
  368. Date: Wed, 6 Dec 1995 09:46:47 GMT
  369. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  370.  
  371. In article <9512051830.AA53505@kandor.isi.edu>,
  372. Craig S. Steele <steele@isi.edu> wrote:
  373. >I'm trying to benchmark block copy rates of various sizes for PowerPCs.  My 
  374. >results are disappointing for the 604, and cause me to wonder what it is I 
  375. >don't understand. Testing on a 9500/120, to which I have limited access, gives 
  376. >the following results for copy code using 32-bit integer and 64-bit double 
  377. >load and stores, respectively:
  378. >
  379. >Asm lvector copy of  1024 doubles in  44.8 nS/acc,  5.4 clocks/acc,  85.1 MB/s
  380. >Asm dvector copy of  1024 doubles in  34.1 nS/acc,  4.1 clocks/acc, 111.9 MB/s
  381.  
  382. OK, in regular "bytes", you appear to be moving (for examples sake)
  383.  8192 bytes
  384.  from address (say) 0x1000000
  385.  to  address (say)  0x1002100.
  386.  
  387. So you are reading 8K and writing 8K as I read it... in a perfect world 
  388. all of your data would fit (precisely) into the L1 d cache.
  389.  
  390. >The source array is aligned to 4K, the destination array to 4K+0x100, to avoid 
  391. >possible aliasing interlocks.  The source array is preloaded immediately 
  392. >before the copy routine is called, so I would expect everything to run at L1 
  393. >cache rates.
  394.  
  395. Except that you are sharing that L1 with things like interrupt tasks, 68K
  396. interrupt tasks (which invoke the emulator causing additional pollution),
  397. and so on.
  398.  
  399. Since as far as I know, there is no way to completely shut off PowerPC
  400. interrupts, quantifying the effect of background processes on your cache 
  401. population can be a bit tricky.
  402.  
  403. >I would naively expect the copy code to average about 1.5 clocks per load or 
  404. >store.  Instead, my code reports over 4 clocks/access.  The code uses the 
  405. >time-base register for timing, which shouldn't cause significant cache 
  406. >disturbance.
  407.  
  408. When you say per access, do you mean per double "moved" as in a read and 
  409. a write, or per double accessed, as in the read or the write alone?
  410.  
  411. I guess I can work it out: 110MB/s (say it's 120 for arguments sake) is 
  412. about 1MB per million clocks (at 120MHz). Or about a byte moved per clock, or
  413. a double moved per 8 clocks. OK so that's 4 per double read, 4 per 
  414. double write (on average).
  415.  
  416. Suggestions:
  417.  1. Plot speed versus vector length. Look for nonlinearities.
  418.    (deliberately shrink or grow the vector).
  419.  
  420.  2. wiggle that 256 byte offset factor some more. or make it zero.
  421.     I do not think the 4-wayness would become a problem until you went
  422.     above 8K vectors, then very little would help...
  423.  
  424.  3. think about cache hinting at or near the bottom of the loop.
  425.     if for some reason a cache line which you are going to read from
  426.     has been dropped, it's good to schedule its re-fetch as far ahead as 
  427.     possible. I'm sure Tim Olson can elaborate much more better good :)
  428.  
  429.  4. I hear Exponential Technology has a faster BiCMOS 604 coming...
  430.  
  431. Rob Barris
  432. Quicksilver Software Inc.
  433. rbarris@quicksilver.com
  434. * opinions expressed not necessarily those of my employer *
  435.  
  436. +++++++++++++++++++++++++++
  437.  
  438. >From steele@isi.edu (Craig S. Steele)
  439. Date: Wed,  6 Dec 1995 12:41:15 -0800
  440. Organization: USC Information Sciences Institute
  441.  
  442. In article <rbarrisDJ5sHz.MJy@netcom.com>, rbarris@netcom.com (Robert Barris) 
  443. writes:
  444. > In article <9512051830.AA53505@kandor.isi.edu>, Craig S. Steele 
  445. > <steele@isi.edu> wrote: 
  446. > >I'm trying to benchmark block copy rates of various sizes for 
  447. > >PowerPCs.  My results are disappointing for the 604, and cause me 
  448. > >to wonder what it is I don't understand. Testing on a 9500/120, to 
  449. > >which I have limited access, gives the following results for copy 
  450. > >code using 32-bit integer and 64-bit double load and stores, 
  451. > >respectively: 
  452. > > 
  453. > >Asm lvector copy of  1024 doubles in  44.8 nS/acc,  5.4 clocks/acc,  85.1 
  454. MB/s
  455. > >Asm dvector copy of  1024 doubles in  34.1 nS/acc,  4.1 clocks/acc, 111.9 
  456. MB/s
  457.  
  458. > So you are reading 8K and writing 8K as I read it... in a perfect 
  459. > world all of your data would fit (precisely) into the L1 d cache. 
  460. Exactly.  However, I did benchmark a range of copy sizes from 512B to 1MB; the 
  461. quoted 8KB block results were the fastest.  Needless to say the rate for 
  462. larger blocks dropped precipitously as the sizes busted (burst?) the L1 and L2 
  463. caches.
  464.  
  465. > >...so I would expect everything to run at L1 cache rates.  
  466. > Except that you are sharing that L1 with things like interrupt 
  467. > tasks, 68K interrupt tasks (which invoke the emulator causing 
  468. > additional pollution), and so on. 
  469. True.  I would have thought that at least some of my trials would have fit in 
  470. between interrupts, e.g., the critical part of the 8KB case only takes about 
  471. 100uS, and the smaller proportionately less. I also tried back-to-back copy 
  472. calls, producing essentially identical results. I did get _much_ worse results 
  473. when I experimented with using the MacOS Microseconds call for timing, so the 
  474. cache pollution issue is very real.  What is the highest rate interrupt source 
  475. on an idle PowerMac anyway?.  Is Microseconds non-native?  I'm clueless.
  476.  
  477. > Since as far as I know, there is no way to completely shut off 
  478. > PowerPC interrupts, quantifying the effect of background processes on 
  479. > your cache population can be a bit tricky. 
  480. I believe I know how to do it on an 8100 (although not the 9500) so it's 
  481. probably worth a (probable deathcookies) experiment to see it if makes a 
  482. difference there.  I deeply regret having blown up our only hardware prototype 
  483. last month...  Maybe next week I'll have a bare machine again, knock on 
  484. Formica(TM).
  485.  
  486. > >I would naively expect the copy code to average about 1.5 clocks per 
  487. > >load or store.  Instead, my code reports over 4 clocks/access.
  488. > I guess I can work it out ... OK so that's 4 per double 
  489. > read, 4 per double write (on average). 
  490. Yes.
  491.  
  492. > Suggestions: 
  493. >  1. Plot speed versus vector length. Look for nonlinearities. 
  494. >    (deliberately shrink or grow the vector).
  495. For a 9500/120:
  496. 512B    49 MB/s
  497. 1KB    68
  498. 2KB    87
  499. 4KB    109
  500. 8KB    112
  501. 16KB    68
  502. 32KB    62
  503. 64KB    54
  504. 128KB    53
  505. 256KB    40
  506. 512KB    35
  507. 1024KB    32
  508.  
  509. The trends are reasonable, it's just the L1 peak rate that seems very low to 
  510. me.  The 6100 and 8100, on the other hand, have some huge huge anomalous dips 
  511. for 128KB operations, presumably managing to evict the code from both the L1 & 
  512. L2 unified caches in some particularly malign way.
  513.  
  514. >  2. wiggle that 256 byte offset factor some more. or make it zero. 
  515. Zero makes things about 10% slower, but I haven't yet tried other offsets.
  516.  
  517. >  3. think about cache hinting at or near the bottom of the loop. 
  518. >     if for some reason a cache line which you are going to read from 
  519. >     has been dropped, it's good to schedule its re-fetch as far ahead 
  520. >     as possible.
  521. A prior load loop is supposed to have ensured that the source is in the cache, 
  522. but this is a good suggestion to double check that assumption, and probably 
  523. the right thing to do for a general-purpose copy where cache status is 
  524. uncontrolled.  I'll check this out.
  525.  
  526. >  4. I hear Exponential Technology has a faster BiCMOS 604 coming... 
  527. That certainly does look interesting, "only" $14million capitalization, but 
  528. good credentials.  Unfortunately, I have to put something under the tree for 
  529. this Christmas, can't wait for that rosy glow ("Is it Rudolph or is it 
  530. bipolar?") we might see next. :-)
  531.  
  532.  
  533.  
  534. Craig S. Steele - Not yet Institutionalized
  535.  
  536.  
  537.  
  538. +++++++++++++++++++++++++++
  539.  
  540. >From tim@apple.com (Tim Olson)
  541. Date: 7 Dec 1995 03:33:26 GMT
  542. Organization: Apple Computer, Inc. / Somerset
  543.  
  544. In article <9512051830.AA53505@kandor.isi.edu>
  545. steele@isi.edu (Craig S. Steele) writes:
  546.  
  547. > I would naively expect the copy code to average about 1.5 clocks per load or 
  548. > store.  Instead, my code reports over 4 clocks/access.  The code uses the 
  549. > time-base register for timing, which shouldn't cause significant cache 
  550. > disturbance.
  551. > Can anyone contradict, corroborate, or explain my poor results?
  552.  
  553. I did a number of measurements awhile back which showed that a 604 can
  554. perform the loop you gave (without the DCBZ) at about 1.3 cycles per
  555. doubleword loaded or stored -- this was done by measuring the runtime
  556. of copying a 64-byte block over many iterations, so both source and
  557. destination were in the cache.  The DCBZ instruction spends multiple
  558. cycles clearing the allocated cache block, so that will add some
  559. overhead (I don't have my spec with me -- I seem to remember it is 4
  560. cycles), which should bring it to somewhere around 15 cycles per loop
  561. iteration, or about 1.8 cycles per doubleword, which is still far less
  562. than your reported 4 cycles.
  563.  
  564. First, try running without the DCBZ to see if it more closely matches
  565. my results (~1.3 cycles per doubleword); if not, then you might be
  566. forgetting about some multiplication factor when using the timebase
  567. register.  On the 604, it increments every 4th bus clock.
  568.  
  569.         -- Tim Olson
  570.         Apple Computer, Inc. / Somerset
  571.         tim@apple.com
  572.  
  573. +++++++++++++++++++++++++++
  574.  
  575. >From cliffc@ami.sps.mot.com (Cliff Click)
  576. Date: 7 Dec 95 09:23:08
  577. Organization: none
  578.  
  579. steele@isi.edu (Craig S. Steele) writes:
  580.  
  581. Craig S. Steele <steele@isi.edu> wrote: 
  582. >I'm trying to benchmark block copy rates of various sizes for 
  583. >PowerPCs.  My results are disappointing for the 604, and cause me 
  584. >to wonder what it is I don't understand. Testing on a 9500/120, to 
  585. >which I have limited access, gives the following results for copy 
  586. >code using 32-bit integer and 64-bit double load and stores, 
  587. >respectively: 
  588.  
  589. Have you tried using "lmw" and "stmw" instead of "lfd" and "stfd"?
  590. My 604 book sez these are #regs+2 cycles each, whilst the float
  591. operations are 3 cycles each.  For large enough blocks, you should
  592. win on the lmw and stmw.
  593.  
  594. Cliff
  595. --
  596. Cliff Click                  Compiler Researcher & Designer
  597. RISC Software, Motorola      PowerPC Compilers
  598. cliffc@risc.sps.mot.com      (512) 891-7240
  599.  
  600. +++++++++++++++++++++++++++
  601.  
  602. >From tim@apple.com (Tim Olson)
  603. Date: 8 Dec 1995 02:59:57 GMT
  604. Organization: Apple Computer, Inc. / Somerset
  605.  
  606. In article <CLIFFC.95Dec7092308@ami.sps.mot.com>
  607. cliffc@ami.sps.mot.com (Cliff Click) writes:
  608.  
  609. > Have you tried using "lmw" and "stmw" instead of "lfd" and "stfd"?
  610. > My 604 book sez these are #regs+2 cycles each, whilst the float
  611. > operations are 3 cycles each.  For large enough blocks, you should
  612. > win on the lmw and stmw.
  613.  
  614. The lfd instruction has a 3-cycle latency for using the result of the
  615. load in a floating-point operation, but the issue-rate of lfd is one
  616. per cycle.  When pipelined in the manner used in the block copy code,
  617. it can transfer at close to one doubleword per cycle.
  618.  
  619. Load and store multiple instructions can achieve close to one word per
  620. cycle for large transfers, but that is half the bandwith of the
  621. lfd/stfd solution.
  622.  
  623.  
  624.         -- Tim Olson
  625.         Apple Computer, Inc. / Somerset
  626.         tim@apple.com
  627.  
  628. +++++++++++++++++++++++++++
  629.  
  630. >From Mark Williams <Mark@streetly.demon.co.uk>
  631. Date: Thu, 07 Dec 95 18:25:26 GMT
  632. Organization: Streetly Software
  633.  
  634.  
  635. In article <CLIFFC.95Dec7092308@ami.sps.mot.com>, Cliff Click writes:
  636.  
  637. > steele@isi.edu (Craig S. Steele) writes:
  638. > Craig S. Steele <steele@isi.edu> wrote: 
  639. > >I'm trying to benchmark block copy rates of various sizes for 
  640. > >PowerPCs.  My results are disappointing for the 604, and cause me 
  641. > >to wonder what it is I don't understand. Testing on a 9500/120, to 
  642. > >which I have limited access, gives the following results for copy 
  643. > >code using 32-bit integer and 64-bit double load and stores, 
  644. > >respectively: 
  645. > Have you tried using "lmw" and "stmw" instead of "lfd" and "stfd"?
  646. > My 604 book sez these are #regs+2 cycles each, whilst the float
  647. > operations are 3 cycles each.  For large enough blocks, you should
  648. > win on the lmw and stmw.
  649. > Cliff
  650. > --
  651. > Cliff Click                  Compiler Researcher & Designer
  652. > RISC Software, Motorola      PowerPC Compilers
  653. > cliffc@risc.sps.mot.com      (512) 891-7240
  654.  
  655. But surely the point is that lfd & stfd have a _latency_ of 3 cycles, but a
  656. throughput of 1 instruction per cycle, whereas the lmw/stmw have both a latency
  657. and throughput of 1 instruction per #regs+2 cycles. That means the lfd/stfd
  658. method should be able to move (ie load and store) 1 word per cycle, while the
  659. lmw/stmw cannot do better than 1 word every 2 cycles (and even with 28 regs
  660. available it would take 60 cycles to move 28 words).
  661.  
  662. - --------------------------------------
  663. Mark Williams<Mark@streetly.demon.co.uk>
  664.  
  665. +++++++++++++++++++++++++++
  666.  
  667. >From tjrob@bluebird.flw.att.com (Tom Roberts)
  668. Date: Sat, 9 Dec 1995 19:19:22 GMT
  669. Organization: AT&T Bell Laboratories
  670.  
  671. In article <4a89nd$hrp@cerberus.ibmoto.com>, Tim Olson <tim@apple.com> wrote:
  672. >In article <CLIFFC.95Dec7092308@ami.sps.mot.com>
  673. >cliffc@ami.sps.mot.com (Cliff Click) writes:
  674. >
  675. >> Have you tried using "lmw" and "stmw" instead of "lfd" and "stfd"?
  676. >> My 604 book sez these are #regs+2 cycles each, whilst the float
  677. >> operations are 3 cycles each.  For large enough blocks, you should
  678. >> win on the lmw and stmw.
  679. >
  680. >The lfd instruction has a 3-cycle latency for using the result of the
  681. >load in a floating-point operation, but the issue-rate of lfd is one
  682. >per cycle.  When pipelined in the manner used in the block copy code,
  683. >it can transfer at close to one doubleword per cycle.
  684. >
  685. >Load and store multiple instructions can achieve close to one word per
  686. >cycle for large transfers, but that is half the bandwith of the
  687. >lfd/stfd solution.
  688.  
  689. In practical systems, memory bandwidth is MUCH more important than
  690. the number of instructions used or their throughput or latency.
  691. (This assumes that the data actually resides in memory, not just in the
  692. cache. This also assumes a "long" loop, so the code is in the icache.)
  693.  
  694. In systems which run the 604 at 1:1 clocking (i.e. internal CPU clock
  695. equals external bus clock), memory bandwidth can be 2-4 times slower than
  696. simple calculations. This is due to cache-access limitations and the
  697. fact that both the CPU and the bus access unit are competing for
  698. access to the cache. In this mode the memory essentially NEVER
  699. overlaps address and data tenures on the bus (halving memory bandwidth);
  700. there are usually several bus clocks between succesive cycles, reducing
  701. bandwidth even more.
  702.  
  703. With 1.5:1 clocking this effect is reduced -- the cache can handle
  704. one access per internal clock, so there is a cycle available to the
  705. CPU between every 2 bus accesses. At 2:1 this effect should disappear,
  706. as the CPU can get every other cycle, and keep up with the memory
  707. bus bandwidth.
  708.  
  709. Note that only recently have 604 chips been shipping which can go 1.5:1
  710. at 66 MHz bus clock.
  711.  
  712. Tom Roberts    tjrob@iexist.att.com
  713.  
  714. ---------------------------
  715.